package cn.lanqiao.springbootproject.controller;

import cn.lanqiao.springbootproject.entity.Menu;
import cn.lanqiao.springbootproject.service.MenuService;
import cn.lanqiao.springbootproject.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Menu)控制层
 *
 * @author david
 * @since 2024-09-28 09:47:27
 */

@RestController
@RequestMapping("/menu")
@CrossOrigin // 线上不需要 （要注掉）
public class MenuController {
    /**
     * 服务对象
     */
    @Autowired
    private MenuService menuService;

    /**
     * 导出查询
     *
     * @param roleId
     * @return Menu
     */
    @Cacheable(value = "roleId",key = "#roleId")
    @GetMapping("/query/{roleId}")
    public Result getMenuList(@PathVariable("roleId") int roleId) {
        List<Menu> list = menuService.getMenuListByRoleId(roleId);
        return Result.success(list);
    }

}
